#include "stdlib.hpp"
#include <purewell/sharedmemory.hpp>

namespace purewell
{
PWSharedMemory::PWSharedMemory()
{
}

PWSharedMemory::~PWSharedMemory()
{
}

bool
PWSharedMemory::initialize(const char* path, int omode, int perm)
{
	int fd(shm_open(path, omode, perm));
	if ( -1 == fd ) return false;
	if ( attach(fd) )
	{
		m_name = path;
		m_fd = fd;
		return true;
	}

	::close(fd);
	return false;
}

bool
PWSharedMemory::unlink(void)
{
	const bool res( 0 == shm_unlink(m_name.c_str()));
	if ( res )
	{
		m_name.clear();
	}

	return res;
}

};//namespace purewell

